﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_GetDefineQueryDocument]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_GetDefineQueryDocument];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_GetDefineQueryDocument]
    @SelectColumns as nvarchar(3000),
    @Conditions as nvarchar(3000),
    @FlowID int 
AS
BEGIN
SET NOCOUNT ON;

DECLARE @SQL NVARCHAR(4000);

SET @SQL = 
'SELECT ' +
    @SelectColumns + '
    FROM (SELECT     a.*,Doc_Builder_ID,Doc_Added_date,Doc_Status,step_id,isrunning,obj_id,obj_type,c.*,d.*
        FROM 
            uds_flow_Style_Data a,
            uds_flow_document b,
            uds_staff c,
            uds_flow d
        WHERE     a.Doc_ID         = b.Doc_ID 
            and b.flow_id         = d.flow_id
            and b.doc_builder_id     = c.staff_id
            and b.isrunning = 1        
             and b.flow_id= ' + cast(@FlowID as nvarchar) + ') T WHERE ' + @Conditions
print @sql;
EXEC (@SQL);

END
GO